package com.example.mapper;

import com.example.pojo.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentMapper {
    @Insert("insert into comment(article_id,user_id,content,create_time,pregnant,parent_id) values(#{articleId},#{userId},#{content},#{createTime},#{pregnant},#{parentId})")
    void add(Comment comment);

    @Select("select * from comment where article_id=#{articleId} and parent_id = 0")
    List<Comment> list(Integer articleId);

    @Update("update comment set pregnant = 1 where id = #{parentId}")
    void makepregnant(Integer parentId);

    @Select("select * from comment where parent_id = #{parentId}")
    List<Comment> listChild(Integer parentId);

    @Select("select user_id from comment where id = #{parentId}")
    Integer getUseridByParentId(Integer parentId);
}
